//
// C++ Interface: lwoloader
//
// Description: 
//
//
// Author: Branan Riley <branan@gmail.com>, (C) 2008
//
// Copyright: See COPYING file that comes with this distribution
//
//
#ifndef LWOLOADER_H
#define LWOLOADER_H

#include "modelloader.h"

#include <physfs.h>

class LwoLoader : public ModelLoader
{
  Q_OBJECT
  public:
    LwoLoader(QObject *parent = 0);
    ~LwoLoader();

    bool loadFile(const QString &filename);

    float *vertices() {
      float *tmp;
      tmp = new float[_num_vert_elements];
      memcpy(tmp, _vertices, _num_vert_elements*4);
      return tmp;
    }

    unsigned int *indices() {
      unsigned int *tmp;
      tmp = new unsigned int[_num_indices];
      memcpy(tmp, _indices, _num_indices*4);
      return tmp;
    }

    unsigned int numIndices() {
      return _num_indices;
    }

  private:
    bool checkFileType(PHYSFS_file *file);
    void loadPntsChunk(PHYSFS_file *file);
    void loadPolsChunk(PHYSFS_file *file);
    PHYSFS_uint32 readVariableIndex(PHYSFS_file *file);
    void skipChunk(PHYSFS_file*);

    float *_vertices;
    unsigned int *_indices;
    float *_normals;
    float *_texcoords;
    unsigned int _num_vert_elements;
    unsigned int _num_indices;
};

#endif
